//
//  BaseCollectionViewController.swift
//  Edaixi-iOS
//
//  Created by 刘树华 on 2017/11/27.
//  Copyright © 2017年 刘树华. All rights reserved.
//

import Foundation
import UIKit

class BaseCollectionViewController: UICollectionViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        collectionView?.backgroundColor = UIColor.white
    }
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        if MBProgressHUD(for: view) != nil{
            canCancelCurrentNetWork()
        }
    }
    func canCancelCurrentNetWork()  {
        
    }
    func contentRect() ->CGRect {
        
        var content = view.bounds
        if !statusBarHidden {
            content.origin.y = content.origin.y + STATUSBAR_HEIGHT
        }
        if !navigationBarHidden {
            content.origin.y = content.origin.y + 44
        }
        content.size.height = content.size.height - content.origin.y
        if let tabControler = self.tabBarController {
            if !tabControler.tabBar.isHidden{
                content.size.height = content.size.height - UITABBAR_HEIGHT
            }else{
                if IS_IPHONEX {
                    content.size.height = content.size.height - 34
                }
            }
        }
        
        return content
    }
    
    func contentBGView () -> UIView {
        
        return view
    }
    
    func changePageStatus(status : PageStatus)  {
        switch status {
        case .success:
            _=contentBGView().subviews.map{ if $0 is PageStatusView { $0.removeFromSuperview() } }
        case .failed(let code):
            _=contentBGView().subviews.map{ if $0 is PageStatusView { $0.removeFromSuperview()}}
            let page = PageStatusView(status: PageStatus.failed(code))
            
            page.frame = CGRect(x: 0, y: 0, width: contentRect().size.width, height: contentRect().size.height)
            contentBGView().addSubview(page)
            break
            
        }
    }
}
